package Reminder.view;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import Reminder.dao.RemindDao;
import Reminder.dao.UserDao;
import Reminder.dao.impl.RemindDaoImpl;
import Reminder.dao.impl.UserDaoImpl;
import Reminder.domain.Message;


import java.awt.*;
import java.io.IOException;
import java.text.ParseException;

public class Controller {


    public Controller() { }


//    public Message loadUserInfo() throws IOException, ParseException {
//        UserDao userDao = new UserDaoImpl();
//        return userDao.getUserData();
//    }
    public Message saveUserInfo(JSONObject userInfo) throws IOException {
        UserDao userDao = new UserDaoImpl();
        return userDao.setUserData(userInfo);
    }
    public Message loadRemindList() throws IOException, ParseException {
        RemindDao remindDao = new RemindDaoImpl();
        return remindDao.getRemindData(GlobalConfig.USER_ID);
    }
    public Message saveRemindList(JSONArray remindList) throws IOException, ParseException {
        RemindDao remindDao = new RemindDaoImpl();
        return remindDao.setRemindData(GlobalConfig.USER_ID,remindList);

    }
    public void displayTray(String title,String content,String type) throws AWTException {

        //Obtain only one instance of the SystemTray object
        SystemTray tray = SystemTray.getSystemTray();

        //If the icon is a file
        Image image = Toolkit.getDefaultToolkit().createImage("icon.png");
        //Alternative (if the icon is on the classpath):
        //Image image = Toolkit.getDefaultToolkit().createImage(getClass().getResource("icon.png"));

        TrayIcon trayIcon = new TrayIcon(image, "Tray Demo");
        //Let the system resize the image if needed
        trayIcon.setImageAutoSize(true);
        //Set tooltip text for the tray icon
        trayIcon.setToolTip("System tray icon demo");
        tray.add(trayIcon);
        System.out.println(TrayIcon.MessageType.INFO);
        switch (type){
            case "info":{
                trayIcon.displayMessage(title, content, TrayIcon.MessageType.INFO);
                break;
            }
            case "error":{
                trayIcon.displayMessage(title, content, TrayIcon.MessageType.ERROR);
                break;
            }
            case "warning":{
                trayIcon.displayMessage(title, content, TrayIcon.MessageType.WARNING);
                break;
            }
            case "none":{
                trayIcon.displayMessage(title, content, TrayIcon.MessageType.NONE);
                break;
            }
        }
    }
}

